        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>ContactManager class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="ContactManager">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/ContactManager.html">ContactManager</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>ContactManager</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class ContactManager implements PairCallback {
 BroadPhase broadPhase;
 Contact contactList;
 int contactCount;
 ContactFilter contactFilter;
 ContactListener contactListener;

 final World pool;

 ContactManager(World argPool) :
   contactList = null,
   contactCount = 0,
   contactFilter = new ContactFilter(),
   contactListener = null,
   broadPhase = new BroadPhase(),
   pool = argPool { }

 /**
  * Broad-phase callback.
  */
 void addPair(Fixture fixtureA, Fixture fixtureB) {
   Body bodyA = fixtureA.body;
   Body bodyB = fixtureB.body;

   // Are the fixtures on the same body?
   if (bodyA == bodyB) {
     return;
   }

   // Does a contact already exist?
   ContactEdge edge = bodyB.contactList;
   while (edge != null) {
     if (edge.other == bodyA) {
       Fixture fA = edge.contact.fixtureA;
       Fixture fB = edge.contact.fixtureB;
       if (fA == fixtureA &amp;&amp; fB == fixtureB) {
         // A contact already exists.
         return;
       }

       if (fA == fixtureB &amp;&amp; fB == fixtureA) {
         // A contact already exists.
         return;
       }
     }

     edge = edge.next;
   }

   // Does a joint override collision? is at least one body dynamic?
   if (bodyB.shouldCollide(bodyA) == false) {
     return;
   }

   // Check user filtering.
   if (contactFilter != null &amp;&amp; 
       contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
     return;
   }

   // Call the factory.
   Contact c = pool.popContact(fixtureA, fixtureB);

   // Contact creation may swap fixtures.
   fixtureA = c.fixtureA;
   fixtureB = c.fixtureB;
   bodyA = fixtureA.body;
   bodyB = fixtureB.body;

   // Insert into the world.
   c.prev = null;
   c.next = contactList;
   if (contactList != null) {
     contactList.prev = c;
   }
   contactList = c;

   // Connect to island graph.

   // Connect to body A
   c.edge1.contact = c;
   c.edge1.other = bodyB;

   c.edge1.prev = null;
   c.edge1.next = bodyA.contactList;
   if (bodyA.contactList != null) {
     bodyA.contactList.prev = c.edge1;
   }
   bodyA.contactList = c.edge1;

   // Connect to body B
   c.edge2.contact = c;
   c.edge2.other = bodyA;

   c.edge2.prev = null;
   c.edge2.next = bodyB.contactList;
   if (bodyB.contactList != null)
     bodyB.contactList.prev = c.edge2;
   bodyB.contactList = c.edge2;

   ++contactCount;
 }

 void findNewContacts() { broadPhase.updatePairs(this); }

 void destroy(Contact c) {
   Fixture fixtureA = c.fixtureA;
   Fixture fixtureB = c.fixtureB;
   Body bodyA = fixtureA.body;
   Body bodyB = fixtureB.body;

   if (contactListener != null &amp;&amp; c.touching) {
     print('touching - end contact');
     contactListener.endContact(c);
   }

   // Remove from the world.
   if (c.prev != null)
     c.prev.next = c.next;

   if (c.next != null)
     c.next.prev = c.prev;

   if (c == contactList)
     contactList = c.next;

   // Remove from body 1
   if (c.edge1.prev != null)
     c.edge1.prev.next = c.edge1.next;

   if (c.edge1.next != null)
     c.edge1.next.prev = c.edge1.prev;

   if (c.edge1 == bodyA.contactList)
     bodyA.contactList = c.edge1.next;

   // Remove from body 2
   if (c.edge2.prev != null)
     c.edge2.prev.next = c.edge2.next;

   if (c.edge2.next != null)
     c.edge2.next.prev = c.edge2.prev;

   if (c.edge2 == bodyB.contactList)
     bodyB.contactList = c.edge2.next;

   // Call the factory.
   pool.pushContact(c);
   --contactCount;
 }

 /**
  * This is the top level collision call for the time step. Here
  * all the narrow phase collision is processed for the world
  * contact list.
  */
 void collide() {
   // Update awake contacts.
   Contact c = contactList;
   while (c != null) {
     Fixture fixtureA = c.fixtureA;
     Fixture fixtureB = c.fixtureB;
     Body bodyA = fixtureA.body;
     Body bodyB = fixtureB.body;


     if (bodyA.awake == false &amp;&amp; bodyB.awake == false) {
       c = c.next;
       continue;
     }

     // is this contact flagged for filtering?
     if ((c.flags &amp; Contact.FILTER_FLAG) == Contact.FILTER_FLAG) {
       // Should these bodies collide?
       if (bodyB.shouldCollide(bodyA) == false) {
         Contact cNuke = c;
         c = cNuke.next;
         destroy(cNuke);
         continue;
       }

       // Check user filtering.
       if (contactFilter != null &amp;&amp;
           contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
         Contact cNuke = c;
         c = cNuke.next;
         destroy(cNuke);
         continue;
       }

       // Clear the filtering flag.
       c.flags &amp;= ~Contact.FILTER_FLAG;
     }

     DynamicTreeNode proxyIdA = fixtureA.proxy;
     DynamicTreeNode proxyIdB = fixtureB.proxy;

     bool overlap = broadPhase.testOverlap(proxyIdA, proxyIdB);

     // Here we destroy contacts that cease to overlap in the broad-phase.
     if (overlap == false) {
       Contact cNuke = c;
       c = cNuke.next;
       destroy(cNuke);
       continue;
     }

     // The contact persists.
     c.update(contactListener);
     c = c.next;
   }
 }
}
</pre>
</div>
<h3>Implements</h3>
<p>
<span class="type-box"><span class="icon-class"></span><a href="../box2d/PairCallback.html">PairCallback</a></span></p>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="ContactManager">
<button class="show-code">Code</button>
new <strong>ContactManager</strong>(<a href="../box2d/World.html">World</a> argPool) <a class="anchor-link" href="#ContactManager"
              title="Permalink to ContactManager.ContactManager">#</a></h4>
<div class="doc">
<pre class="source">
ContactManager(World argPool) :
 contactList = null,
 contactCount = 0,
 contactFilter = new ContactFilter(),
 contactListener = null,
 broadPhase = new BroadPhase(),
 pool = argPool { }
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="broadPhase">
<button class="show-code">Code</button>
<a href="../box2d/BroadPhase.html">BroadPhase</a>         <strong>broadPhase</strong> <a class="anchor-link"
            href="#broadPhase"
            title="Permalink to ContactManager.broadPhase">#</a>
        </h4>
        <div class="doc">
<pre class="source">
broadPhase
</pre>
</div>
</div>
<div class="field"><h4 id="contactCount">
<button class="show-code">Code</button>
int         <strong>contactCount</strong> <a class="anchor-link"
            href="#contactCount"
            title="Permalink to ContactManager.contactCount">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contactCount
</pre>
</div>
</div>
<div class="field"><h4 id="contactFilter">
<button class="show-code">Code</button>
<a href="../box2d/ContactFilter.html">ContactFilter</a>         <strong>contactFilter</strong> <a class="anchor-link"
            href="#contactFilter"
            title="Permalink to ContactManager.contactFilter">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contactFilter
</pre>
</div>
</div>
<div class="field"><h4 id="contactList">
<button class="show-code">Code</button>
<a href="../box2d/Contact.html">Contact</a>         <strong>contactList</strong> <a class="anchor-link"
            href="#contactList"
            title="Permalink to ContactManager.contactList">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contactList
</pre>
</div>
</div>
<div class="field"><h4 id="contactListener">
<button class="show-code">Code</button>
<a href="../box2d/ContactListener.html">ContactListener</a>         <strong>contactListener</strong> <a class="anchor-link"
            href="#contactListener"
            title="Permalink to ContactManager.contactListener">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contactListener
</pre>
</div>
</div>
<div class="field"><h4 id="pool">
<button class="show-code">Code</button>
final <a href="../box2d/World.html">World</a>         <strong>pool</strong> <a class="anchor-link"
            href="#pool"
            title="Permalink to ContactManager.pool">#</a>
        </h4>
        <div class="doc">
<pre class="source">
pool
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="addPair">
<button class="show-code">Code</button>
void <strong>addPair</strong>(<a href="../box2d/Fixture.html">Fixture</a> fixtureA, <a href="../box2d/Fixture.html">Fixture</a> fixtureB) <a class="anchor-link" href="#addPair"
              title="Permalink to ContactManager.addPair">#</a></h4>
<div class="doc">
<p>Broad-phase callback.</p>
<pre class="source">
void addPair(Fixture fixtureA, Fixture fixtureB) {
 Body bodyA = fixtureA.body;
 Body bodyB = fixtureB.body;

 // Are the fixtures on the same body?
 if (bodyA == bodyB) {
   return;
 }

 // Does a contact already exist?
 ContactEdge edge = bodyB.contactList;
 while (edge != null) {
   if (edge.other == bodyA) {
     Fixture fA = edge.contact.fixtureA;
     Fixture fB = edge.contact.fixtureB;
     if (fA == fixtureA &amp;&amp; fB == fixtureB) {
       // A contact already exists.
       return;
     }

     if (fA == fixtureB &amp;&amp; fB == fixtureA) {
       // A contact already exists.
       return;
     }
   }

   edge = edge.next;
 }

 // Does a joint override collision? is at least one body dynamic?
 if (bodyB.shouldCollide(bodyA) == false) {
   return;
 }

 // Check user filtering.
 if (contactFilter != null &amp;&amp; 
     contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
   return;
 }

 // Call the factory.
 Contact c = pool.popContact(fixtureA, fixtureB);

 // Contact creation may swap fixtures.
 fixtureA = c.fixtureA;
 fixtureB = c.fixtureB;
 bodyA = fixtureA.body;
 bodyB = fixtureB.body;

 // Insert into the world.
 c.prev = null;
 c.next = contactList;
 if (contactList != null) {
   contactList.prev = c;
 }
 contactList = c;

 // Connect to island graph.

 // Connect to body A
 c.edge1.contact = c;
 c.edge1.other = bodyB;

 c.edge1.prev = null;
 c.edge1.next = bodyA.contactList;
 if (bodyA.contactList != null) {
   bodyA.contactList.prev = c.edge1;
 }
 bodyA.contactList = c.edge1;

 // Connect to body B
 c.edge2.contact = c;
 c.edge2.other = bodyA;

 c.edge2.prev = null;
 c.edge2.next = bodyB.contactList;
 if (bodyB.contactList != null)
   bodyB.contactList.prev = c.edge2;
 bodyB.contactList = c.edge2;

 ++contactCount;
}
</pre>
</div>
</div>
<div class="method"><h4 id="collide">
<button class="show-code">Code</button>
void <strong>collide</strong>() <a class="anchor-link" href="#collide"
              title="Permalink to ContactManager.collide">#</a></h4>
<div class="doc">
<p>This is the top level collision call for the time step. Here
all the narrow phase collision is processed for the world
contact list.</p>
<pre class="source">
void collide() {
 // Update awake contacts.
 Contact c = contactList;
 while (c != null) {
   Fixture fixtureA = c.fixtureA;
   Fixture fixtureB = c.fixtureB;
   Body bodyA = fixtureA.body;
   Body bodyB = fixtureB.body;


   if (bodyA.awake == false &amp;&amp; bodyB.awake == false) {
     c = c.next;
     continue;
   }

   // is this contact flagged for filtering?
   if ((c.flags &amp; Contact.FILTER_FLAG) == Contact.FILTER_FLAG) {
     // Should these bodies collide?
     if (bodyB.shouldCollide(bodyA) == false) {
       Contact cNuke = c;
       c = cNuke.next;
       destroy(cNuke);
       continue;
     }

     // Check user filtering.
     if (contactFilter != null &amp;&amp;
         contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
       Contact cNuke = c;
       c = cNuke.next;
       destroy(cNuke);
       continue;
     }

     // Clear the filtering flag.
     c.flags &amp;= ~Contact.FILTER_FLAG;
   }

   DynamicTreeNode proxyIdA = fixtureA.proxy;
   DynamicTreeNode proxyIdB = fixtureB.proxy;

   bool overlap = broadPhase.testOverlap(proxyIdA, proxyIdB);

   // Here we destroy contacts that cease to overlap in the broad-phase.
   if (overlap == false) {
     Contact cNuke = c;
     c = cNuke.next;
     destroy(cNuke);
     continue;
   }

   // The contact persists.
   c.update(contactListener);
   c = c.next;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="destroy">
<button class="show-code">Code</button>
void <strong>destroy</strong>(<a href="../box2d/Contact.html">Contact</a> c) <a class="anchor-link" href="#destroy"
              title="Permalink to ContactManager.destroy">#</a></h4>
<div class="doc">
<pre class="source">
void destroy(Contact c) {
 Fixture fixtureA = c.fixtureA;
 Fixture fixtureB = c.fixtureB;
 Body bodyA = fixtureA.body;
 Body bodyB = fixtureB.body;

 if (contactListener != null &amp;&amp; c.touching) {
   print('touching - end contact');
   contactListener.endContact(c);
 }

 // Remove from the world.
 if (c.prev != null)
   c.prev.next = c.next;

 if (c.next != null)
   c.next.prev = c.prev;

 if (c == contactList)
   contactList = c.next;

 // Remove from body 1
 if (c.edge1.prev != null)
   c.edge1.prev.next = c.edge1.next;

 if (c.edge1.next != null)
   c.edge1.next.prev = c.edge1.prev;

 if (c.edge1 == bodyA.contactList)
   bodyA.contactList = c.edge1.next;

 // Remove from body 2
 if (c.edge2.prev != null)
   c.edge2.prev.next = c.edge2.next;

 if (c.edge2.next != null)
   c.edge2.next.prev = c.edge2.prev;

 if (c.edge2 == bodyB.contactList)
   bodyB.contactList = c.edge2.next;

 // Call the factory.
 pool.pushContact(c);
 --contactCount;
}
</pre>
</div>
</div>
<div class="method"><h4 id="findNewContacts">
<button class="show-code">Code</button>
void <strong>findNewContacts</strong>() <a class="anchor-link" href="#findNewContacts"
              title="Permalink to ContactManager.findNewContacts">#</a></h4>
<div class="doc">
<pre class="source">
void findNewContacts() { broadPhase.updatePairs(this); }
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
